using Nekonya.Managers;
using TinaX;
using TinaX.I18N;
using TinaX.UIKit;
using TinaX.XComponent;
using UniRx;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

namespace Nekonya.UI
{
    /// <summary>
    /// 入口菜单 UI控制器
    /// </summary>
    public class EntryMenuScreen : XUIBehaviour
    {
        [Binding("btn_EnterScene")]
        public Button Btn_EnterScene { get; set; }

        [Binding("btn_About")]
        public Button Btn_About { get; set; }

        [Binding("btn_LanguageSwitch")]
        public Button Btn_SwitchLanguage { get; set; }

        [Binding("btn_Quit")]
        public Button Btn_QuitGame { get; set; }

        [Inject]
        public IGlobalManager GlobalManager { get; set; }

        [Inject]
        public II18N I18N { get; set; }

        [Inject]
        public IGameModeManager GameModeManager { get; set; }

        private ILocalizerGroup m_LocalizerCommon;

        public override void Awake()
        {
            m_LocalizerCommon = this.I18N.GetGroup();

            Btn_QuitGame.onClick.AddListener(async () =>
            {
                //弹窗
                await GlobalManager.ShowMessageBox_2Btn(m_LocalizerCommon["msgbox_quit_content"],
                    title: m_LocalizerCommon["msgbox_quit_title"],
                    confirmBtnName: m_LocalizerCommon["msgbox_quit_btn_quit"],
                    null,
                    onConfirm: () => 
                    {
                        //执行退出
                        GlobalManager.QuitGame();
                    },
                    onCancel: () => { },
                    useMask: true,
                    closeByMask: false);
            });

            Btn_About.onClick.AddListener(async () =>
            {
                //弹窗
                await GlobalManager.ShowMessageBox_1Btn("这是一个用于教学用途的游戏Demo\n请勿用于其他用途。", "关于游戏");
            });

            Btn_SwitchLanguage.onClick.AddListener(() =>
            {
                //不严谨写法，请勿学习
                if (m_LocalizerCommon["current_i18n"].Equals("hans"))
                    this.I18N.UseRegionAsync("en_us", err => { });
                else
                    this.I18N.UseRegionAsync("hans", err => { });
            });

            Btn_EnterScene.onClick.AddListener(() =>
            {
                GameModeManager.EnterGameRootAsync()
                    .ToObservable()
                    .SubscribeOnMainThread()
                    .Subscribe(_ =>
                    {
                        this.Close();
                    });
            });

        }


    }
}
